<template>
  <Card>
    <Tabs value="一卡通收入">
      <TabPane label="一卡通收入" name="一卡通收入">
        <Form ref="searchCardForm" :label-width="90" :model="searchCardForm" inline>
          <Form-item label="日期范围：" prop="date">
            <DatePicker
              v-model="searchCardForm.date"
              placeholder="请选择日期范围"
              placement="bottom-start"
              style="width: 200px"
              type="daterange"
            ></DatePicker>
          </Form-item>
          <Form-item label="车牌号：" prop="license_plate_num">
            <Input
              v-model="searchCardForm.license_plate_num"
              clearable
              placeholder="支持模糊搜索"
              style="width: 200px"
              type="text"
            />
          </Form-item>
          <Form-item label="车辆线路：" prop="line">
            <Select v-model="searchCardForm.line" clearable placeholder="选择线路" style="width:200px;">
              <Option value="-1">全部</Option>
              <Option v-for="item in lines" :key="item.value" :value="item.value">{{ item.label }}</Option>
            </Select>
          </Form-item>
          <Form-item style="margin-left:-90px;">
            <Button icon="md-search" type="primary" @click="handleSearch('card')">搜索</Button>
            <Button @click="handleReset('card')">重置</Button>
          </Form-item>
        </Form>
        <div class="btns" style="margin-bottom:10px;">
          <upload-file
            ref="uploadCardFile"
            button-name="导入"
            @on-change="uploadData($event, 'card')"
          ></upload-file>
        </div>
        <Table
          :columns="cardColumns"
          :data="cardData"
          :loading="cardLoading"
          border
          size="small"
          stripe
        ></Table>
        <Row class="page" justify="end" type="flex">
          <Page
            :current="searchCardForm.pageNumber"
            :page-size="searchCardForm.pageSize"
            :total="cardTotal"
            show-total
            @on-change="changePage($event, 'card')"
          />
        </Row>
      </TabPane>
      <TabPane label="邮储收入" name="邮储收入">
        <Form ref="searchPostForm" :label-width="90" :model="searchPostForm" inline>
          <Form-item label="日期范围：" prop="date">
            <DatePicker
              v-model="searchPostForm.date"
              placeholder="请选择日期范围"
              placement="bottom-start"
              style="width: 200px"
              type="daterange"
            ></DatePicker>
          </Form-item>
          <Form-item label="车牌号：" prop="license_plate_num">
            <Input
              v-model="searchPostForm.license_plate_num"
              clearable
              placeholder="支持模糊搜索"
              style="width: 200px"
              type="text"
            />
          </Form-item>
          <Form-item label="车辆线路：" prop="line">
            <Select v-model="searchPostForm.line" clearable placeholder="选择线路" style="width:200px;">
              <Option value="-1">全部</Option>
              <Option v-for="item in lines" :key="item.value" :value="item.value">{{ item.label }}</Option>
            </Select>
          </Form-item>
          <Form-item style="margin-left:-90px;">
            <Button icon="md-search" type="primary" @click="handleSearch('post')">搜索</Button>
            <Button @click="handleReset('post')">重置</Button>
          </Form-item>
        </Form>
        <div class="btns" style="margin-bottom:10px;">
          <upload-file
            ref="uploadPostFile"
            button-name="导入"
            @on-change="uploadData($event, 'post')"
          ></upload-file>
        </div>
        <Table :columns="postColumn" :data="postData" :loading="postLoading" border size="small"></Table>
        <Row class="page" justify="end" type="flex">
          <Page
            :current="searchPostForm.pageNumber"
            :page-size="searchPostForm.pageSize"
            :total="postTotal"
            show-total
            @on-change="changePage($event, 'post')"
          />
        </Row>
      </TabPane>
      <TabPane label="现金收入" name="现金收入">
        <Form ref="searchCashForm" :label-width="90" :model="searchCashForm" inline>
          <Form-item label="日期范围：" prop="date">
            <DatePicker
              v-model="searchCashForm.date"
              placeholder="请选择日期范围"
              placement="bottom-start"
              style="width: 200px"
              type="daterange"
            ></DatePicker>
          </Form-item>
          <Form-item label="车牌号：" prop="license_plate_num">
            <Input
              v-model="searchCashForm.license_plate_num"
              clearable
              placeholder="支持模糊搜索"
              style="width: 200px"
              type="text"
            />
          </Form-item>
          <Form-item style="margin-left:-90px;">
            <Button icon="md-search" type="primary" @click="handleSearch('cash')">搜索</Button>
            <Button @click="handleReset('cash')">重置</Button>
          </Form-item>
        </Form>
        <div class="btns" style="margin-bottom:10px;">
          <Button icon="ios-add" target="_self" type="primary" @click="toAdd('cash')">添加</Button>
          <upload-file
            ref="uploadCashFile"
            button-name="导入"
            @on-change="uploadData($event, 'cash')"
          ></upload-file>
          <Button icon="md-trash" type="error" @click="delAll('cash')">删除</Button>
        </div>
        <Row>
          <Alert show-icon>
            已选择
            <span class="select-count">{{ cashSelectCount }}</span> 项
            <a class="select-clear" @click="clearCashSelectAll">清空</a>
          </Alert>
        </Row>
        <Table
          ref="cashTable"
          :columns="cashColumn"
          :data="cashData"
          :loading="cashLoading"
          border
          size="small"
          stripe
          @on-selection-change="showCashSelect"
        >
          <template slot="action" slot-scope="{ row }">
            <a
              class="edit"
              size="small"
              style="color:#2d8cf0;font-size: 12px;"
              type="text"
              @click="edit('cash', row)"
            >编辑</a>
            <Divider type="vertical"/>
            <a class="del" style="color:#ed4014;font-size: 12px;" @click="del('cash', row)">删除</a>
          </template>
        </Table>
        <Row class="page" justify="end" type="flex">
          <Page
            :current="searchCashForm.pageNumber"
            :page-size="searchCashForm.pageSize"
            :total="cashTotal"
            show-total
            @on-change="changePage($event, 'cash')"
          />
        </Row>
      </TabPane>
      <TabPane label="一般包车收入" name="一般包车收入">
        <Form ref="searchCharteredCarForm" :label-width="90" :model="searchCharteredCarForm" inline>
          <!--          <Form-item label="日期范围：" prop="date">-->
          <!--            <DatePicker type="daterange" confirm placement="bottom-start" v-model="searchCharteredCarForm.date"-->
          <!--                        placeholder="请选择日期范围" style="width: 200px"></DatePicker>-->
          <!--          </Form-item>-->
          <Form-item label="车牌号：" prop="license_plate_num">
            <Input
              v-model="searchCharteredCarForm.license_plate_num"
              clearable
              placeholder="支持模糊搜索"
              style="width: 200px"
              type="text"
            />
          </Form-item>
          <Form-item style="margin-left:-90px;">
            <Button icon="md-search" type="primary" @click="handleSearch('charteredCar')">搜索</Button>
            <Button @click="handleReset('charteredCar')">重置</Button>
          </Form-item>
        </Form>
        <div class="btns" style="margin-bottom:10px;">
          <Button icon="ios-add" target="_self" type="primary" @click="toAdd('charteredCar')">添加</Button>
          <Button icon="md-trash" type="error" @click="delAll('charteredCar')">删除</Button>
        </div>
        <Table
          ref="charteredCarTable"
          :columns="charteredCarColumn"
          :data="charteredCarData"
          :loading="charteredCarLoading"
          border
          size="small"
          stripe
          @on-selection-change="showCharteredCarSelect"
        >
          <template slot="action" slot-scope="{ row }">
            <a
              class="edit"
              size="small"
              style="color:#2d8cf0;font-size: 12px;"
              type="text"
              @click="edit('charteredCar', row)"
            >编辑</a>
            <Divider type="vertical"/>
            <a
              class="del"
              style="color:#ed4014;font-size: 12px;"
              @click="del('charteredCar', row)"
            >删除</a>
          </template>
        </Table>
        <Row class="page" justify="end" type="flex">
          <Page
            :current="searchCharteredCarForm.pageNumber"
            :page-size="searchCharteredCarForm.pageSize"
            :total="charteredCarTotal"
            show-total
            @on-change="changePage($event, 'charteredCar')"
          />
        </Row>
      </TabPane>
    </Tabs>
    <Modal v-model="modal" :closable="false" :mask-closable="false" width="360">
      <p slot="header" style="color:#2d8cf0;text-align:center">
        <Icon type="ios-information-circle"></Icon>
        <span>文件上传成功，正在导入数据</span>
      </p>
      <div style="text-align:center">
        <Button :loading="importLoading" long size="large" type="error">导入中...</Button>
      </div>
      <div slot="footer"></div>
    </Modal>
    <Modal v-model="cashModalVisible" :mask-closable="false" :title="cashModalTitle" :width="500">
      <Form ref="cashForm" :label-width="80" :model="cashForm" :rules="cashFormValidate">
        <FormItem label="日期" prop="date">
          <DatePicker
            v-model="cashForm.date"
            format="yyyy-MM-dd"
            placeholder="选择时间"
            type="date"
            @on-change="cashForm.date=$event"
          ></DatePicker>
        </FormItem>
        <FormItem label="车牌号" prop="license_plate_num">
          <Select v-model="cashForm.license_plate_num" clearable filterable placeholder="选择车牌号">
            <Option
              v-for="item in licensePlateNumList"
              :key="item.value"
              :value="item.value"
            >{{ item.label }}
            </Option>
          </Select>
        </FormItem>
        <FormItem label="现金收入" prop="cash_income">
          <InputNumber v-model="cashForm.cash_income" :max="10000000" :min="0" style="width: 100%"></InputNumber>
        </FormItem>
      </Form>
      <div slot="footer">
        <Button type="text" @click="cashHandleCancel">取消</Button>
        <Button :loading="cashSubmitLoading" type="primary" @click="cashHandleSubmit">提交</Button>
      </div>
    </Modal>
    <Modal
      v-model="charteredCarModalVisible"
      :mask-closable="false"
      :title="charteredCarModalTitle"
      :width="500"
    >
      <Form
        ref="charteredCarForm"
        :label-width="80"
        :model="charteredCarForm"
        :rules="charteredCarFormValidate"
      >
        <FormItem label="车牌号" prop="license_plate_num">
          <Select
            v-model="charteredCarForm.license_plate_num"
            clearable
            filterable
            placeholder="选择车牌号"
          >
            <Option
              v-for="item in licensePlateNumList"
              :key="item.value"
              :value="item.value"
            >{{ item.label }}
            </Option>
          </Select>
        </FormItem>
        <FormItem label="开始时间" prop="date_start_at">
          <DatePicker
            v-model="charteredCarForm.date_start_at"
            format="yyyy-MM-dd"
            placeholder="选择时间"
            type="date"
            @on-change="charteredCarForm.date_start_at=$event"
          ></DatePicker>
        </FormItem>
        <FormItem label="结束时间" prop="date_end_at">
          <DatePicker
            v-model="charteredCarForm.date_end_at"
            format="yyyy-MM-dd"
            placeholder="选择时间"
            type="date"
            @on-change="charteredCarForm.date_end_at=$event"
          ></DatePicker>
        </FormItem>
        <FormItem label="包车收入" prop="chartered_income">
          <InputNumber
            v-model="charteredCarForm.chartered_income"
            :max="10000000"
            :min="0"
            style="width: 100%"
          ></InputNumber>
        </FormItem>
      </Form>
      <div slot="footer">
        <Button type="text" @click="charteredCarHandleCancel">取消</Button>
        <Button
          :loading="charteredCarSubmitLoading"
          type="primary"
          @click="charteredCarHandleSubmit"
        >提交
        </Button>
      </div>
    </Modal>
  </Card>
</template>
<script>
import UploadFile from '../my-components/upload-file'
import {licensePlateNumList} from '../../api/bus'
import {
  destroyCash,
  destroyCharteredCar,
  importCard,
  importCash,
  importPost,
  incomeCardList,
  incomeCashList,
  incomeCharteredCarList,
  incomePostList,
  storeCash,
  storeCharteredCar,
  updateCash,
  updateCharteredCar,
} from '../../api/income'

export default {
  components: {
    UploadFile
  },
  data() {
    return {
      cashSelectList: [],
      cashSelectCount: 0,
      cashSubmitLoading: false,
      cashModalType: 0,
      cashModalVisible: false,
      cashModalTitle: '',
      cashForm: {
        date: '',
        license_plate_num: '',
        cash_income: 0
      },
      cashFormValidate: {
        license_plate_num: [
          {
            required: true,
            message: '车牌号不能为空',
            trigger: 'change',
            type: 'string'
          }
        ]
      },
      charteredCarSelectList: [],
      charteredCarSelectCount: 0,
      charteredCarSubmitLoading: false,
      charteredCarModalType: 0,
      charteredCarModalVisible: false,
      charteredCarModalTitle: '',
      charteredCarForm: {
        license_plate_num: '',
        date_start_at: '',
        date_end_at: '',
        chartered_income: 0
      },
      charteredCarFormValidate: {
        license_plate_num: [
          {
            required: true,
            message: '车牌号不能为空',
            trigger: 'change',
            type: 'string'
          }
        ]
      },
      searchCardForm: {
        line: '-1',
        license_plate_num: '',
        date: [null, null],
        pageNumber: 1,
        pageSize: 10
      },
      searchPostForm: {
        line: '-1',
        license_plate_num: '',
        date: [null, null],
        pageNumber: 1,
        pageSize: 10
      },
      searchCashForm: {
        line: '-1',
        license_plate_num: '',
        date: [null, null],
        pageNumber: 1,
        pageSize: 10
      },
      searchCharteredCarForm: {
        license_plate_num: '',
        // date: [null,null],
        pageNumber: 1,
        pageSize: 10
      },
      cardLoading: false,
      postLoading: false,
      cashLoading: false,
      charteredCarLoading: false,
      cardData: [],
      postData: [],
      cashData: [],
      charteredCarData: [],
      licensePlateNumList: [],
      modal: false,
      importLoading: false,
      loading: false,
      cardTotal: 0,
      postTotal: 0,
      cashTotal: 0,
      charteredCarTotal: 0,
      cardColumns: [
        {
          type: 'index',
          width: 60,
          align: 'center'
        },
        {
          title: '日期',
          key: 'date',
          width: 100,
          align: 'center'
        },
        {
          title: '车队',
          key: 'team',
          align: 'center'
        },
        {
          title: '线路',
          key: 'line',
          align: 'center'
        },
        {
          title: '车牌号',
          key: 'license_plate_num',
          align: 'center'
        },
        {
          title: '卡类型',
          key: 'card_type',
          align: 'center'
        },
        {
          title: '扣款次数',
          key: 'charge_count',
          align: 'right'
        },
        {
          title: '免费次数',
          key: 'free_count',
          align: 'right'
        },
        {
          title: '合计次数',
          key: 'total_count',
          align: 'right'
        },
        {
          title: '优惠后金额',
          key: 'discount_after_amt',
          align: 'right'
        },
        {
          title: '优惠前金额',
          key: 'discount_before_amt',
          align: 'right'
        },
        {
          title: '优惠金额',
          key: 'discount_amt',
          align: 'right'
        }
      ],
      postColumn: [
        {
          type: 'index',
          width: 60,
          align: 'center'
        },
        {
          title: '日期',
          key: 'date',
          width: 100,
          align: 'center'
        },
        {
          title: '线路',
          key: 'line',
          align: 'center'
        },
        {
          title: '车牌号',
          key: 'license_plate_num',
          align: 'center'
        },
        {
          title: '自编号',
          key: 'self_numbering',
          align: 'center'
        },
        {
          title: '普通营收',
          key: 'ordinary_amt',
          align: 'right'
        },
        {
          title: '普通运量',
          key: 'ordinary_count',
          align: 'right'
        },
        {
          title: '学生营收',
          key: 'student_amt',
          align: 'right'
        },
        {
          title: '学生运量',
          key: 'student_count',
          align: 'right'
        },
        {
          title: '公益营收',
          key: 'welfare_amt',
          align: 'right'
        },
        {
          title: '公益运量',
          key: 'welfare_count',
          align: 'right'
        },
        {
          title: '营收小计',
          key: 'total_amt',
          align: 'right'
        },
        {
          title: '运量小计',
          key: 'total_count',
          align: 'right'
        }
      ],
      cashColumn: [
        {
          type: 'selection',
          width: 60,
          align: 'center'
        },
        {
          type: 'index',
          width: 60,
          align: 'center'
        },
        {
          title: '日期',
          key: 'date',
          align: 'center'
        },
        {
          title: '车牌号',
          key: 'license_plate_num',
          align: 'center'
        },
        {
          title: '现金收入',
          key: 'cash_income',
          align: 'center'
        },
        {
          title: '操作',
          slot: 'action',
          width: 120,
          fixed: 'right',
          align: 'center'
        }
      ],
      charteredCarColumn: [
        {
          type: 'selection',
          width: 60,
          align: 'center'
        },
        {
          type: 'index',
          width: 60,
          align: 'center'
        },
        {
          title: '车牌号',
          key: 'license_plate_num',
          align: 'center'
        },
        {
          title: '开始时间',
          key: 'date_start_at',
          align: 'center'
        },
        {
          title: '结束时间',
          key: 'date_end_at',
          align: 'center'
        },
        {
          title: '包车收入',
          key: 'chartered_income',
          align: 'center'
        },
        {
          title: '操作',
          slot: 'action',
          width: 175,
          align: 'center'
        }
      ],
      lines: []
    }
  },
  mounted() {
    this.init()
    this.getLinesArray()
  },
  methods: {
    async getLinesArray() {
      this.lines = await this.getLines()
    },
    cashHandleCancel() {
      this.cashModalVisible = false
    },
    cashHandleSubmit() {
      this.$refs.cashForm.validate(valid => {
        if (valid) {
          this.cashSubmitLoading = true
          if (this.cashModalType === 0) {
            // 添加 避免编辑后传入id等数据 记得删除
            delete this.cashForm.id
            storeCash(this.cashForm).then(res => {
              this.cashSubmitLoading = false
              if (res.data) {
                this.$Message.success(res.message)
                this.getIncomeCashList()
                this.cashModalVisible = false
              } else {
                this.$Message.error(res.message)
              }
            })
          } else {
            updateCash(this.cashForm, this.cashForm.id).then(res => {
              this.cashSubmitLoading = false
              if (res.data) {
                this.$Message.success(res.message)
                this.getIncomeCashList()
                this.cashModalVisible = false
              } else {
                this.$Message.error(res.message)
              }
            })
          }
        }
      })
    },
    changePage(v, event) {
      switch (event) {
        case 'card':
          this.searchCardForm.pageNumber = v
          this.getIncomeCardList()
          break
        case 'post':
          this.searchPostForm.pageNumber = v
          this.getIncomePostList()
          break
        case 'cash':
          this.searchCashForm.pageNumber = v
          this.getIncomeCashList()
          break
        case 'charteredCar':
          this.searchCharteredCarForm.pageNumber = v
          this.getIncomeCharteredCarList()
          break
      }
    },
    charteredCarHandleCancel() {
      this.charteredCarModalVisible = false
    },
    charteredCarHandleSubmit() {
      this.$refs.charteredCarForm.validate(valid => {
        if (valid) {
          this.charteredCarSubmitLoading = true
          if (this.charteredCarModalType === 0) {
            // 添加 避免编辑后传入id等数据 记得删除
            delete this.charteredCarForm.id
            storeCharteredCar(this.charteredCarForm).then(res => {
              this.charteredCarSubmitLoading = false
              if (res.data) {
                this.$Message.success(res.message)
                this.getIncomeCharteredCarList()
                this.charteredCarModalVisible = false
              } else {
                this.$Message.error(res.message)
              }
            })
          } else {
            updateCharteredCar(
              this.charteredCarForm,
              this.charteredCarForm.id
            ).then(res => {
              this.charteredCarSubmitLoading = false
              if (res.data) {
                this.$Message.success(res.message)
                this.getIncomeCharteredCarList()
                this.charteredCarModalVisible = false
              } else {
                this.$Message.error(res.message)
              }
            })
          }
        }
      })
    },
    clearCashSelectAll() {
      this.$refs.cashTable.selectAll(false)
    },
    clearCharteredCarSelectAll() {
      this.$refs.charteredCarTable.selectAll(false)
    },
    del(type, row) {
      if (type === 'cash') {
        this.$Modal.confirm({
          title: '确认删除',
          loading: true,
          content: '您确认要删除此条数据吗？',
          onOk: () => {
            const ids = row.id
            // 批量删除
            destroyCash(ids).then(res => {
              this.$Modal.remove()
              if (res.data === true) {
                this.$Message.success(res.message)
                this.getIncomeCashList()
              } else {
                this.$Message.error(res.message)
              }
            })
          }
        })
      } else {
        this.$Modal.confirm({
          title: '确认删除',
          loading: true,
          content: '您确认要删除此条数据吗？',
          onOk: () => {
            const ids = row.id
            // 批量删除
            destroyCharteredCar(ids).then(res => {
              this.$Modal.remove()
              if (res.data === true) {
                this.$Message.success(res.message)
                this.getIncomeCharteredCarList()
              } else {
                this.$Message.error(res.message)
              }
            })
          }
        })
      }
    },
    delAll(type) {
      if (type === 'cash') {
        if (this.cashSelectCount <= 0) {
          this.$Message.warning('您还未选择要删除的数据')
          return
        }
        this.$Modal.confirm({
          title: '确认删除',
          loading: true,
          content: '您确认要删除所选的 ' + this.cashSelectCount + ' 条数据？',
          onOk: () => {
            let ids = ''
            this.cashSelectList.forEach(function (e) {
              ids += e.id + ','
            })
            ids = ids.substring(0, ids.length - 1)
            // 批量删除
            destroyCash(ids).then(res => {
              this.$Modal.remove()
              if (res.data === true) {
                this.$Message.success(res.message)
                this.getIncomeCashList()
              } else {
                this.$Message.error(res.message)
              }
            })
          }
        })
      } else {
        if (this.charteredCarSelectCount <= 0) {
          this.$Message.warning('您还未选择要删除的数据')
          return
        }
        this.$Modal.confirm({
          title: '确认删除',
          loading: true,
          content:
            '您确认要删除所选的 ' + this.charteredCarSelectCount + ' 条数据？',
          onOk: () => {
            let ids = ''
            this.charteredCarSelectList.forEach(function (e) {
              ids += e.id + ','
            })
            ids = ids.substring(0, ids.length - 1)
            // 批量删除
            destroyCharteredCar(ids).then(res => {
              this.$Modal.remove()
              if (res.data === true) {
                this.$Message.success(res.message)
                this.getIncomeCharteredCarList()
              } else {
                this.$Message.error(res.message)
              }
            })
          }
        })
      }
    },
    edit(type, row) {
      if (type === 'cash') {
        this.cashModalType = 1
        this.cashModalTitle = '编辑'
        this.cashForm = {
          id: row.id,
          date: row.date,
          license_plate_num: row.license_plate_num,
          cash_income: parseFloat(row.cash_income)
        }
        this.cashModalVisible = true
      } else {
        this.charteredCarModalType = 1
        this.charteredCarModalTitle = '编辑'
        this.charteredCarForm = {
          id: row.id,
          date_start_at: row.date_start_at,
          date_end_at: row.date_end_at,
          license_plate_num: row.license_plate_num,
          chartered_income: parseFloat(row.chartered_income)
        }
        this.charteredCarModalVisible = true
      }
    },
    getIncomeCardList() {
      this.cardLoading = true
      incomeCardList(this.searchCardForm).then(res => {
        this.cardLoading = false
        if (res.data) {
          this.cardData = res.data.cardRecord
          this.cardTotal = res.data.count
        }
      })
    },
    getIncomeCashList() {
      this.cashSelectCount = 0
      this.cashSelectList = []
      this.cashLoading = true
      incomeCashList(this.searchCashForm).then(res => {
        this.cashLoading = false
        if (res.data) {
          this.cashData = res.data.cashRecord
          this.cashTotal = res.data.count
        }
      })
    },
    getIncomeCharteredCarList() {
      this.charteredCarSelectCount = 0
      this.charteredCarSelectList = []
      this.charteredCarLoading = true
      incomeCharteredCarList(this.searchCharteredCarForm).then(res => {
        this.charteredCarLoading = false
        if (res.data) {
          this.charteredCarData = res.data.charteredCarRecord
          this.charteredCarTotal = res.data.count
        }
      })
    },
    getIncomePostList() {
      this.postLoading = true
      incomePostList(this.searchPostForm).then(res => {
        this.postLoading = false
        if (res.data) {
          this.postData = res.data.postRecord
          this.postTotal = res.data.count
        }
      })
    },
    getLicensePlateNumList() {
      licensePlateNumList().then(res => {
        const data = []
        res.data.forEach(function (e, i) {
          data.push({
            label: e,
            value: e
          })
        })
        this.licensePlateNumList = data
      })
    },
    handleReset(event) {
      switch (event) {
        case 'card':
          this.$refs.searchCardForm.resetFields()
          this.searchCardForm.pageNumber = 1
          this.searchCardForm.pageSize = 10
          this.getIncomeCardList()
          break
        case 'post':
          this.$refs.searchPostForm.resetFields()
          this.searchPostForm.pageNumber = 1
          this.searchPostForm.pageSize = 10
          this.getIncomePostList()
          break
        case 'cash':
          this.$refs.searchCashForm.resetFields()
          this.searchCashForm.pageNumber = 1
          this.searchCashForm.pageSize = 10
          this.getIncomeCashList()
          break
        case 'charteredCar':
          this.$refs.searchCharteredCarForm.resetFields()
          this.searchCharteredCarForm.pageNumber = 1
          this.searchCharteredCarForm.pageSize = 10
          this.getIncomeCharteredCarList()
          break
      }
    },
    handleSearch(event) {
      switch (event) {
        case 'card':
          this.searchCardForm.pageNumber = 1
          this.searchCardForm.pageSize = 10
          this.getIncomeCardList()
          break
        case 'post':
          this.searchPostForm.pageNumber = 1
          this.searchPostForm.pageSize = 10
          this.getIncomePostList()
          break
        case 'cash':
          this.searchCashForm.pageNumber = 1
          this.searchCashForm.pageSize = 10
          this.getIncomeCashList()
          break
        case 'charteredCar':
          this.searchCharteredCarForm.pageNumber = 1
          this.searchCharteredCarForm.pageSize = 10
          this.getIncomeCharteredCarList()
          break
      }
    },
    init() {
      this.getIncomeCardList()
      this.getIncomePostList()
      this.getIncomeCashList()
      this.getIncomeCharteredCarList()
      this.getLicensePlateNumList()
    },
    showCashSelect(e) {
      this.cashSelectList = e
      this.cashSelectCount = e.length
    },
    showCharteredCarSelect(e) {
      this.charteredCarSelectList = e
      this.charteredCarSelectCount = e.length
    },
    toAdd(type) {
      if (type === 'cash') {
        this.cashModalType = 0
        this.cashModalTitle = '添加'
        this.$refs.cashForm.resetFields()
        delete this.cashForm.id
        this.cashModalVisible = true
      } else {
        this.charteredCarModalType = 0
        this.charteredCarModalTitle = '添加'
        this.$refs.charteredCarForm.resetFields()
        delete this.charteredCarForm.id
        this.charteredCarModalVisible = true
      }
    },
    uploadData(event, cardType) {
      this.modal = true
      this.importLoading = true
      switch (cardType) {
        case 'card'://一卡通导入
          importCard({url: event.url, mark: false}).then(res => {
            if (res.data) {
              this.$Message.success(res.message)
              this.getIncomeCardList()
            } else {
              const message = res.message
              const url = event.url
              this.$Modal.confirm({
                title: '确认导入',
                content: message,
                onOk: () => {
                  this.modal = true
                  this.importLoading = true
                  importCard({url: url, mark: true}).then(result => {
                    if (result.data) {
                      this.modal = false
                      this.importLoading = false
                      this.$Message.success(result.message)
                      this.getIncomeCardList()
                    }
                  })
                }
              })
            }
            this.modal = false
            this.importLoading = false
          })
          break
        case 'post':
          importPost({url: event.url}).then(res => {
            if (res.data) {
              this.$Message.success(res.message)
              this.getIncomePostList()
            } else {
              this.$Message.error(res.message)
            }
            this.modal = false
            this.importLoading = false
          })
          break
        case 'cash'://现金导入
          importCash({url: event.url, mark: false}).then(res => {
            if (res.data) {
              this.modal = false
              this.importLoading = false
              this.$Message.success(res.message)
              this.getIncomeCashList()
            } else {
              const message = res.message
              const url = event.url
              this.$Modal.confirm({
                title: '确认导入',
                content: message,
                onOk: () => {
                  this.modal = true
                  this.importLoading = true
                  importCash({url: url, mark: true}).then(result => {
                    if (result.data) {
                      this.modal = false
                      this.importLoading = false
                      this.$Message.success(result.message)
                      this.getIncomeCashList()
                    }
                  })
                }
              })
            }
          })
          break
        case 'charteredCar':
          break
      }
    }
  }
}
</script>
<style>
.ivu-tabs .ivu-select-dropdown {
  left: 0 !important;
}
</style>
